package com.hnxxxy.sysmgr.mapper;

import com.hnxxxy.common.redis.RedisMyabtisCstCache;
import com.hnxxxy.sysmgr.pojo.*;
import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;

/**
 * @CLASSDESCRIPER:
 * @AUTHOR:suhui
 * @PHONE:13319575368
 * @EMIAL:13319575368@163.COM
 * @DATE: 2020/3/31
 * @PARAMDESCRIPER:
 * @OUTPARAMDESCRIPER:
 */
@Repository
@Mapper
@CacheNamespace(implementation = RedisMyabtisCstCache.class)
public interface ISysMapper {
    @Select("select * from sys_staff a where a.loginname=#{username} and a.pwd=md5(#{password})")
    public Staff toLogin(String username, String password);

    @Select("select * from sys_project where id=1")
    public Project getProjectInfo();


    @Select("select * from sys_staff_role a,sys_role b where a.roleid=b.id and a.staffid=#{id}")
    List<Role> getStaffRole(Integer id);

    @Select("select distinct aa.*, x.id  menuid,x.menuname,x.url,x.icon,x.parentid,x.type menutype from ( select b.* from sys_role_token a,sys_token b,sys_staff_role c where a.tokenid=b.id and a.roleid=c.roleid and c.staffid=#{id}) aa left JOIN sys_menu x on aa.tokenvalue=x.id")
    List<Token> getStaffToken(Integer id);


    /** 以下是提供给shiro中自定义Realm的方法**/
    @Select("select * from sys_staff a where a.loginname=#{username}")
    Staff findByName(String username);
    /** 以下是提供给shiro中自定义Realm的方法**/
    @Select("select distinct a.roleid from sys_staff_role a where a.staffid=#{id}")
    Set<String> findRolesByStaffId(Integer id);
    @Select("select distinct b.tokenvalue from sys_role_token a,sys_token b,sys_staff_role c where a.tokenid=b.id and a.roleid=c.roleid and c.staffid=#{id}")
    Set<String> findPremsByStaffId(Integer id);

    @Select("select *  from sys_dict a where a.groupid=#{groupid}")
    List<Dict> getSelectList(String groupid);
}
